# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=poco
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.0
pkgrel=2
pkgdesc="POrtable COmponents C++ Libraries (mingw-w64)"
arch=('any')
url="http://pocoproject.org"
license=("boost")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-expat"
         "${MINGW_PACKAGE_PREFIX}-libmariadbclient"
         "${MINGW_PACKAGE_PREFIX}-openssl"
         "${MINGW_PACKAGE_PREFIX}-pcre"
         "${MINGW_PACKAGE_PREFIX}-sqlite3"
         "${MINGW_PACKAGE_PREFIX}-zlib")
options=('staticlibs' 'strip')
source=(http://pocoproject.org/releases/${_realname}-${pkgver}/${_realname}-${pkgver}-all.tar.gz
        001-WIN32-defines-instead-hardcoded-values.patch
        002-enable-C++11-if-compiler-supports-it.patch
        003-check-for-WIN64-and-enable-LLP64-schema.patch
        004-format-string-using-ostringstream.patch
        005-dont-compare-signed-unsigned.patch
        006-include-some-Win32-libs-to-compile.patch
        007-MinGW-doesnt-implement-wide-character-startup-module.patch
        008-Add-Mingw32-W64-configuration.patch
        009-Fix-compilation-on-WIN64-target.patch
        010-remove-warnings.patch
        011-cmake-mingw.patch
        012-find-mysql.patch
        013-POCO_WIN32_UTF8-redefinition.patch
        100-fix-mingw-config.patch)
sha256sums=('ed1be29ee413141269e7ccee861b11a2992a9f70072dbb28bec31ad432d71cab'
            '0ebf7f290e934453eb8e2330312f0393d7d40a61e4e7ec95c78a777363831398'
            '8f25725da17c31e0a48583c267cc7aac58bd0201927db49a2c39328a8721b6ea'
            'bcaa21c08aec0936a25fe387ecd93e354149a404a610b5a23870b047e5c1525f'
            'a1b95fea2c4464f25a9ddee6f2c559d391a22ae0cddda3537adf22f1258ec482'
            'ac05804b1c90d682333cb18dbc4aedc9e12508779e93edbd59d9b82d353b0013'
            '5d07a1746166dbecab8cb4d857e8257776e05f1ab15125e744d1d9c8dd42dde7'
            'b51d192291b973185021431070654a3ac82e8f2b38780235aa5e71b44c5a0074'
            '61979c75b5577b9b0bf3fb96045b3c299a38c5dfc5048895ade73400831eb975'
            '0e940b8ca756c43b0455862d6e95a999740c53fe63d0f9cefd27811f9ac9984a'
            '532f91576ff18deeb52fdfc9f660febb8a29d0dc9b18f2eded4974177d379c2d'
            '0d8bef1423099a4d43ce58250df504f3cbf4366099ad68538cf7df5c69d0abf2'
            '8022b4de8b605932fd11ac879a288f52bf385784247db0b00cf5cee7f6d4c0f3'
            '57ca988afad8dfd73705f677a706518d635aea2936d4de8f35ad9943c9a4b1b0'
            '1dacb602e0163d0eb871b38fab411c3b89df1c5e5c505038931704b30b517776')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}-all
  patch -p1 -i ${srcdir}/001-WIN32-defines-instead-hardcoded-values.patch
  patch -p1 -i ${srcdir}/002-enable-C++11-if-compiler-supports-it.patch
  patch -p1 -i ${srcdir}/003-check-for-WIN64-and-enable-LLP64-schema.patch
  patch -p1 -i ${srcdir}/004-format-string-using-ostringstream.patch
  patch -p1 -i ${srcdir}/005-dont-compare-signed-unsigned.patch
  patch -p1 -i ${srcdir}/006-include-some-Win32-libs-to-compile.patch
  patch -p1 -i ${srcdir}/007-MinGW-doesnt-implement-wide-character-startup-module.patch
  patch -p1 -i ${srcdir}/008-Add-Mingw32-W64-configuration.patch
  patch -p1 -i ${srcdir}/009-Fix-compilation-on-WIN64-target.patch
  patch -p1 -i ${srcdir}/010-remove-warnings.patch
  patch -p1 -i ${srcdir}/011-cmake-mingw.patch
  patch -p1 -i ${srcdir}/012-find-mysql.patch
  patch -p1 -i ${srcdir}/013-POCO_WIN32_UTF8-redefinition.patch
  patch -p1 -i ${srcdir}/100-fix-mingw-config.patch
}

build() {
  local _config=
  case "${CARCH}" in
    i686)
      _config=MinGW
    ;;

    x86_64)
      _config=MinGW32-W64
    ;;
  esac

  CXXFLAGS+=" -std=c++11"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DPOCO_UNBUNDLED=ON \
    -DENABLE_MONGODB=OFF \
    ../${_realname}-${pkgver}-all

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make destdir=${pkgdir} install
}
